<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_counter_model extends CI_Model {

    //put your code here


    function __construct() {
        parent::__construct();
        log_message('debug', 'Init Model Initialized');
    }
    
 function count_listing($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('profile');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    /*function count_photos($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('photos');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }
*/
    function count_logos($status=Null) {
        $this->db->where('image <>', 'no-logo.png',$status);
        $query = $this->db->get('lawyer_master');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_banners() {
        $this->db->where('file <>', 'nobanner.gif');
        $query = $this->db->get('banner');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_videos($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('videos');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    function count_categories($status=Null) {
        $this->db->where('status', $status);
        $query = $this->db->get('category_tree');
        if ($query->num_rows() > 0) {
            return $query->num_rows();
        } else {
            return 0;
        }
    }

    

    //joy
    function count_record($tableName=NULL, $fieldName=NULL, $fieldValue=NULL) {

        $sql = "Select count(*)as total from $tableName where $fieldName=$fieldValue ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_record_member($tableName=NULL, $fieldName=NULL) {

        $sql = "Select count(*)as total from $tableName";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_member() {
        $sql = "Select count(*)as total from member where status <>98";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_incorrect_report() {
        $sql = "Select count(*)as total from report_incorrect_master where status =51";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_enquiry() {
        $sql = "Select count(*)as total from message where prefix='ENQ'";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--subha
    function count_review() {
        $sql = "Select count(*)as total from review_master";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    //--Member Area Counter detail

    function listing_total_view($id=Null) {
        $sql = "Select viewed as total from business_master where id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_listing_email_enquiry($id=Null) {
        $sql = "Select count(*)as total from enquiry_master where mode='EMAIL' and listing_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function count_listing_SMS_enquiry($id=Null) {
        $sql = "Select count(*)as total from enquiry_master where mode='SMS' and listing_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

    function listing_counter_by_id($id) {
        $sql = "Select count(*) as total from business_master where mem_id=$id";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }
    
    
    
    //-------Count State by country id------------
    
    
    function state_count($country_id) {
    	if ($country_id) {
    		$code = trim($country_id);
    		$sql = "Select count(*)as total from state where countryid=$code";
    		
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return '0';
    	}
    }
    //-------Count City by State id------------
    
    function city_count($cat_id=NULL) {
    	if ($cat_id) {
    		$code = trim($cat_id);
    		$sql = "Select count(*)as total from city where stateid='$code'";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return '0';
    	}
    }
    
    function count_cat($cat_id=NULL) {
    	if ($cat_id) {
    		$code = trim($cat_id);
    		$sql = "Select count(*)as total from category_tree where parent_id='$code'";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return '0';
    	}
    }
    
    //--------------Count all records from any table ----------------
    function count_all_record($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    
    //--Active pagination -- rahul sinha--//
    function count_all_business($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    //--Inactive Pagination-- rahul sinha--//
    function count_inactive_business($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('business_master');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    //--Active pagination -- rahul sinha--//
    function count_all_banner($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }

function count_inactive_banner($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('banner');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    function count_all_reviews($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    function count_inactive_reviews($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('review_master');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    function count_all_photos($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    
    function count_inactive_photos($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('photos');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    function count_all_videos($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    function count_inactive_videos($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('videos');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    function count_inactive_news_report($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('news');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }

    function count_all_members($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    
    function count_inactive_members($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('member');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    //--------------Count all records from any table ----------------
    function count_all_messages($tblname='') {
    	if ($tblname) {
    		$sql = "Select count(*)as total from $tblname ";
    		$query = $this->db->query($sql);
    		$row = $query->row();
    		if ($row->total != 0)
    			return $row->total;
    		else
    			return 0;
    	}else {
    		return 0;
    	}
    }
    function count_all_category($parent_id=0) {
    	$this->db->where('parent_id', $parent_id);
    	$query = $this->db->get('category_tree');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
    
    
    function countKeyword($status=Null) {
    	$this->db->where('status', $status);
    	$query = $this->db->get('term');
    	if ($query->num_rows() > 0) {
    		return $query->num_rows();
    	} else {
    		return 0;
    	}
    }
}
